<?php


namespace app\plugins\goods\admin\model;


use think\model\concern\SoftDelete;

class GoodsCates extends \app\common\plugins\PluginModel
{
    use SoftDelete;

    protected $name = 'goods_cates';

    protected $autoWriteTimestamp = true;
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';
    protected $defaultSoftDelete = null;

    protected $schema = [
        'id' => 'int',
        'title' => 'string',
        'sort' => 'int',
        'status' => 'int',
        'pid' => 'int',
        'pic' => 'int',
        'createtime' => 'int',
        'updatetime' => 'int',
        'deletetime' => 'int',
    ];

    protected $submitField = [
        'status' => 'int',

    ];

    protected $append = [
        'status_text',
        'pic_url'
    ];

    protected function getStatusTextAttr($value,$data){
        if(!isset($data['status'])){
            return '';
        }
        $status = ['禁用','启用'];
        return $status[$data['status']];
    }

    protected function getPicUrlAttr($value,$data){
        if(!isset($data['pic'])){
            return '';
        }
        return get_file_path($data['pic']);
    }
    protected function setAttrStatus($data){
        if(isset($data['status'])){
            return 1;
        }

        return 0;
    }


}